home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / paralleltest.c < prev    next >
C/C++ Source or Header  |  1986-01-07  |  2KB  |  112 lines

  1.  
  2. /* parallel test program v1.1 */
  3.  
  4. #include        "exec/types.h"
  5. #include        "exec/nodes.h"
  6. #include        "exec/lists.h"
  7. #include        "exec/ports.h"
  8. #include        "exec/libraries.h"
  9. #include        "exec/devices.h"
  10. #include        "exec/io.h"
  11. #include        "devices/parallel.h"
  12.  
  13. struct IOExtPar IORpar;
  14. struct MsgPort *port;
  15. char   buffer[64000];
  16. extern struct MsgPort *CreatePort();
  17.  
  18. main()
  19. {
  20.     int     error;
  21.     int     actual;
  22.     unsigned char pflags;
  23.     unsigned long pt0;
  24.     unsigned long pt1;
  25.  
  26. open:
  27.  /* OPEN the parallel.device */
  28.     if ((error = OpenDevice (PARALLELNAME, 0, &IORpar, 0)) != 0) {
  29.         printf ("bad news %ld on Open \n", error);
  30.         exit (error);
  31.     }
  32.  
  33.  /* SET UP the message port in the I/O request */
  34.     port = CreatePort (PARALLELNAME,0);
  35.     IORpar.IOPar.io_Message.mn_ReplyPort = port;
  36.  
  37. /*    SET PARAMS for the parallel.device */
  38.     pflags = PARF_EOFMODE;
  39.     pt0  = 0x51040303;
  40.     pt1  = 0x03030303;
  41.  
  42.   if ((error = setparams (pflags,pt0,pt1)) != 0) {
  43.         printf ("bad news %ld on setup \n", error);  
  44.         exit (error);    /* redundant err msg, but who's counting ?? */
  45.     } 
  46.  
  47.     actual = readPar (buffer,60000);
  48.  
  49.  /* CLOSE the parallel.device */
  50.     CloseDevice (&IORpar);
  51.     DeletePort (port);
  52.     exit (0);
  53. }
  54.  
  55.  /* PARALLEL I/O functions */
  56.  
  57. setparams(pf,ta0,ta1)
  58.  
  59.     unsigned char pf;
  60.     unsigned long ta0;
  61.     unsigned long ta1;
  62.  
  63. {
  64.     int error;
  65.  
  66.     IORpar.io_ParFlags      = pf;
  67.     IORpar.IOPar.io_Command = PDCMD_SETPARAMS;
  68.     IORpar.io_PTermArray.PTermArray0 = ta0;
  69.     IORpar.io_PTermArray.PTermArray1 = ta1;
  70.  
  71.     if ((error = DoIO (&IORpar)) != 0) {
  72.         printf ("parallel.device setparams error %ld \n", error);
  73.         exit (1);
  74.     }
  75.     return (error);
  76. }
  77.  
  78. readPar(data,length)
  79.     char *data;
  80.     ULONG length;
  81. {
  82.     int error;
  83.  
  84.     IORpar.IOPar.io_Data = data;
  85.     IORpar.IOPar.io_Length = length;
  86.     IORpar.IOPar.io_Command = CMD_READ;
  87.  
  88.     if ((error = DoIO (&IORpar)) != 0) {
  89.         printf ("parallel.device read error %ld \n", error);
  90.         exit (1);
  91.     }
  92.     return (IORpar.IOPar.io_Actual);
  93. }
  94.  
  95.  
  96. writePar(data,length)
  97.     char *data;
  98.     int length;
  99. {
  100.     int     error;
  101.  
  102.     IORpar.IOPar.io_Data = data;
  103.     IORpar.IOPar.io_Length = length;
  104.     IORpar.IOPar.io_Command = CMD_WRITE;
  105.  
  106.     if ((error = DoIO (&IORpar)) != 0) {
  107.         printf ("parallel.device write error %ld \n", error);
  108.         exit (1);
  109.     }
  110.     return (error);
  111. }
  112.